home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / demos / a-d / amms / ratioseg.s < prev    next >
Encoding:
Text File  |  1995-08-22  |  13.9 KB  |  418 lines

  1.     opt    l-,c-,e+
  2.  
  3.     INCDIR    "Include/"
  4.     INCLUDE    "mb/Main.i"
  5.     INCLUDE "mb/User.i"
  6.     INCLUDE "mb/Text.i"
  7.  
  8. *************************************************
  9. *    V1.14
  10. * NAME      : UDRate_Unit
  11. *
  12. * FUNKTION: Berechnung der Download/Upload-Ratio
  13. *        - Steht im Brettkommentar ein ONLYBYTE: am Anfang, so
  14. *          wird nur die Byteratio beim Upload und Download benutzt
  15. *        - Steht im Brettkommentar ein ONLYDOWN: am Anfang, so
  16. *          wird nur die Downloadratio beim Upload und Download benutzt
  17. *        - Steht im Brettkommentar ein BYTE: am Anfang, so
  18. *          wird nur die Byteratio beim Upload benutzt,
  19. *          beim Download wird Byteratio und im Fehlerfall die
  20. *          Downloadratio benutzt
  21. *        - Steht im Brettkommentar ein DOWN: am Anfang, so
  22. *          wird nur die Downloadratio beim Upload benutzt,
  23. *          beim Download wird Downloadratio und im Fehlerfall die
  24. *          Byteratio benutzt
  25. *        - Sonst sind beide Ratios aktiv, mind. eine muss erfuellt sein
  26. *        Nach folgender Methode wird Upload/Download-Ratio berechnet :
  27. *        - Restdownloadanzahl = Restdownloadanzahl + Ratio
  28. *        - Restdownloadbytes = Restdownloadbytes + Ratio * Filelaenge
  29. *          Restdownloadbytes werden in KByte angegeben und gespeichert !
  30. *        - Wenn beide Aktiv, so muss mind. fuer den Download ein Fall
  31. *          erfuellt sein, es werden bei beiden Abzuege bzw. Zugaben
  32. *          vorgenommen
  33. *
  34. *    Update: 13-Aug-1995
  35. *************************************************
  36.  
  37. RatioB_UpByte:    equ    0        ; Bitnr: Byteratio-Upload
  38. RatioB_DoByte:    equ    1        ; Bitnr: Byteratio-Download
  39. RatioB_UpDown:    equ    2        ; Bitnr: Downratio-Upload
  40. RatioB_DoDown:    equ    3        ; Bitnr: Downratio-Download
  41. RatioB_ErrByte:    equ    4        ; Bitnr: Byteratio-Ersatzdownload
  42. RatioB_ErrDown:    equ    5        ; Bitnr: Downratio-Ersatzdownload
  43. RatioF_UpByte:    equ    1<<RatioB_UpByte ; Byteratio-Upload
  44. RatioF_DoByte:    equ    1<<RatioB_DoByte ; Byteratio-Download
  45. RatioF_UpDown:    equ    1<<RatioB_UpDown ; Downratio-Upload
  46. RatioF_DoDown:    equ    1<<RatioB_DoDown ; Downratio-Download
  47. RatioF_ErrByte:    equ    1<<RatioB_ErrByte ; Byteratio-Ersatzdownload
  48. RatioF_ErrDown:    equ    1<<RatioB_ErrDown ; Downratio-Ersatzdownload
  49.  
  50.  
  51.     moveq    #0,d0
  52.     rts
  53.     jmp    TestDownload
  54.     jmp    AddDownload
  55.     jmp    SubDownload
  56.     jmp    AddUpload
  57.     dc.l    T_Version
  58.  
  59.  
  60. *************************************************
  61. *
  62. * NAME      : TestDownload
  63. *
  64. * FUNKTION: Pruefe, ob weiterer Download moeglich
  65. *
  66. * INPUT      : d0.l: Laenge des Download-Files
  67. *        d7.w: Filebrettnummer (-1=kein Filebrett)
  68. *
  69. * OUTPUT  : keine
  70. *    N-Bit: Download nicht moeglich
  71. *************************************************
  72. TestDownload:
  73.  movem.l d0/d4/a0,-(sp)            ; Register retten
  74.  
  75.  bsr WhichRatio                ; Ratioart in d4 holen
  76.  
  77.  move.l Main_User(a5),a0        ; Zeiger auf Userdaten in a0
  78.  
  79. ** Restdownloads pruefen
  80.  
  81.  bclr #RatioB_DoDown,d4            ; Download-Ratio erlaubt ?
  82.  beq.s TestDownload_Down_End        ; Nein, verzw.
  83. TestDownload_Down:
  84.  bclr #RatioB_ErrDown,d4        ; Ersatz-Download-Ratio verbieten
  85.  tst.w UserDat_DownLeft(a0)        ; Restdownloads vorhanden ?
  86.  bne.s TestDownload_OK            ; Ja, verzw.
  87.  btst #RatioB_ErrByte,d4        ; Byte-Ratio im Fehlerfall nutzen ?
  88.  bne.s TestDownload_Byte        ; Ja, verzw.
  89. TestDownload_Down_End:
  90.  
  91. ** Restdownloadbytes pruefen
  92.  
  93.  bclr #RatioB_DoByte,d4            ; Byte-Ratio erlaubt ?
  94.  beq.s TestDownload_Error        ; Nein, verzw.
  95. TestDownload_Byte:
  96.  bclr #RatioB_ErrByte,d4        ; Ersatz-Byte-Ratio verbieten
  97.   add.l #512,d0                ; Filelaenge in KByte umrechnen,
  98.   lsr.l #8,d0                ; runde dabei in der Mitte
  99.   lsr.l #2,d0                ; d0=(d0+512)/1024
  100.  cmp.l UserDat_DownBytesLeft(a0),d0    ; Genug Restdownloadbytes vorhanden ?
  101.  bls.s TestDownload_OK            ; Ja, verzw.
  102.  btst #RatioB_ErrDown,d4        ; Download-Ratio im Fehlerfall nutzen ?
  103.  bne.s TestDownload_Down        ; Ja, verzw.
  104.  bra.s TestDownload_Error        ; Nein, verzw.
  105.  
  106. ** Status auf OK stellen
  107.  
  108. TestDownload_OK:
  109.  moveq #0,d0                ; Status auf OK stellen
  110.  
  111. ** Ende
  112.  
  113. TestDownload_End:
  114.  movem.l (sp)+,d0/d4/a0            ; Register holen
  115.  rts
  116.  
  117. ** Status auf Fehler setzen
  118.  
  119. TestDownload_Error:
  120.  moveq #-1,d0                ; Status auf Fehler stellen
  121.  bra.s TestDownload_End            ; -> Ende
  122.  
  123.  
  124.  
  125. *************************************************
  126. *
  127. * NAME      : AddDownload
  128. *
  129. * FUNKTION: Ein Download-File aus Download-Restdaten abziehen
  130. *        IM Buffer werden Daten fuer den eventuellen
  131. *        SubDownload()-Aufruf gespeichert
  132. *
  133. * INPUT      : d0.l: Laenge des Download-Files
  134. *        d7.w: Filebrettnummer (-1=kein Filebrett)
  135. *        a0.l: Zeiger auf Buffer (Laenge=File_RatioSeg_Buf_Size)
  136. *
  137. * OUTPUT  : keine
  138. *    N-Bit: Download nicht moeglich
  139. *************************************************
  140. AddDownload:
  141.  movem.l d0-d2/d4/a6,-(sp)        ; Register retten
  142.  
  143.  bsr WhichRatio                ; Ratioart in d4 holen
  144.  
  145.  move.l Main_UserLib(a5),a6        ; Userbase in a6
  146.  jsr User_WaitON(a6)            ; User-Zugriff sperren
  147.  move.l Main_User(a5),a6        ; Zeiger auf Userdaten in a6
  148.  moveq #-1,d2                ; Status: N-Bit (Fehler)
  149.  
  150. ** Restdownloadanzahl erniedrigen
  151.  
  152.  clr.w File_RatioSeg_Buf_Downloads(a0)    ; Abgezogene Download-Anzahl loeschen
  153.  bclr #RatioB_DoDown,d4            ; Download-Ratio erlaubt ?
  154.  beq.s AddDownLoad_SubDown_End        ; Nein, verzw.
  155. AddDownload_SubDown:
  156.  bclr #RatioB_ErrDown,d4        ; Ersatz-Download-Ratio verbieten
  157.  move.w UserDat_DownLeft(a6),d1        ; Restdownloadanzahl in d1
  158.  bne.s AddDownLoad_SubDown_Start    ; Wenn Restdownloads, verzw.
  159.  btst #RatioB_ErrByte,d4        ; Byte-Ratio im Fehlerfall nutzen ?
  160.  bne.s AddDownload_Byte            ; Ja, verzw.
  161.  bra.s AddDownLoad_SubDown_End
  162. AddDownLoad_SubDown_Start:
  163.  cmp.w #UserDat_DownLeft_Unlimited,d1    ; Unendlich viele Restdownloads ?
  164.  beq.s AddDownload_SubDown_OK        ; Ja, verzw.
  165.  subq.w #1,d1                ; Restdownloadanzahl erniedrigen
  166.  addq.w #1,File_RatioSeg_Buf_Downloads(a0) ; Abgezogene Download-Anzahl speichern
  167.  move.w d1,UserDat_DownLeft(a6)        ; Restdownloadanzahl speichern
  168. AddDownload_SubDown_OK:
  169.  moveq #0,d2                ; Status: N'-Bit (OK)
  170. AddDownLoad_SubDown_End:
  171.  
  172. ** Restdownloadbytes erniedrigen
  173.  
  174.  clr.l File_RatioSeg_Buf_DownBytes(a0)    ; Abgezogene Downloadbytes loeschen
  175.  bclr #RatioB_DoByte,d4            ; Byte-Ratio erlaubt ?
  176.  beq.s AddDownload_Byte_End        ; Nein, verzw.
  177. AddDownload_Byte:
  178.  bclr #RatioF_ErrByte,d4        ; Ersatz-Byte-Ratio verbieten
  179.  move.l UserDat_DownBytesLeft(a6),d1    ; Restdownloadbytes in d1
  180.  cmp.l #UserDat_DownBytesLeft_Unlimited,d1 ; Unendlich viele Restdownloadbytes ?
  181.  beq.s AddDownload_Byte_OK        ; Ja -> Ende mit OK
  182.   add.l #512,d0                ; Filelaenge in KByte umrechnen,
  183.   lsr.l #8,d0                ; runde dabei in der Mitte
  184.   lsr.l #2,d0                ; d0=(d0+512)/1024
  185.  cmp.l d1,d0                ; Genug Bytes vorhanden ?
  186.  bls.s AddDownload_Byte_Dec        ; Ja, verzw.
  187.  tst.w d2                ; Status noch auf Fehler ?
  188.  bpl.s AddDownload_Byte_SimulateOK    ; Nein, verzw.
  189.  btst #RatioB_ErrDown,d4        ; Download-Ratio im Fehlerfall nutzen ?
  190.  bne.s AddDownload_SubDown        ; Ja, verzw.
  191.  bra.s AddDownLoad_Byte_End
  192. AddDownload_Byte_SimulateOK:
  193.  move.l d1,d0                ; Downloadbytes fuer Null erniedrigen
  194. AddDownload_Byte_Dec:
  195.  move.l d0,File_RatioSeg_Buf_DownBytes(a0) ; Abgezogene Downloadbytes speichern
  196.  sub.l d0,d1                ; Restdownloadbytes erniedrigen
  197.  move.l d1,UserDat_DownBytesLeft(a6)    ; Restdownloadbytes speichern
  198. AddDownload_Byte_OK:
  199.  moveq #0,d2                ; Status: N'-Bit (OK)
  200. AddDownload_Byte_End:
  201.  
  202. ** Ende
  203.  
  204.  move.l Main_UserLib(a5),a6        ; Userbase in a6
  205.  jsr User_WaitOFF(a6)            ; User-Zugriff erlauben
  206.  tst.w d2                ; Status-Bit setzen
  207.  movem.l (sp)+,d0-d2/d4/a6        ; Register holen
  208.  rts
  209.  
  210.  
  211.  
  212. *************************************************
  213. *
  214. * NAME      : SubDownload
  215. *
  216. * FUNKTION: Ein Download-File wegen Abbruch zu Download-Restdaten wieder
  217. *        addieren. Im Buffer stehen Daten vom AddDownload()-Aufruf.
  218. *
  219. * INPUT      : a0.l: Zeiger auf Buffer (Laenge=File_RatioSeg_Buf_Size)
  220. *
  221. * OUTPUT  : keine
  222. *
  223. *************************************************
  224. SubDownload:
  225.  movem.l d1/a6,-(sp)            ; Register retten
  226.  
  227.  move.l Main_UserLib(a5),a6        ; Userbase in a6
  228.  jsr User_WaitON(a6)            ; User-Zugriff sperren
  229.  move.l Main_User(a5),a6        ; Zeiger auf Userdaten in a6
  230.  
  231. ** Restdownloadanzahl erhoehen
  232.  
  233.  move.w UserDat_DownLeft(a6),d1        ; Restdownloadanzahl in d1
  234.  cmp.w #UserDat_DownLeft_Unlimited,d1    ; Unendlich viele Restdownloads ?
  235.  beq.s SubDownload_AddBytes        ; Ja -> Ende
  236.  cmp.w #UserDat_DownLeft_Max,d1        ; Max. Anzahl erreicht ?
  237.  beq.s SubDownload_AddBytes        ; Ja, verzw.
  238.  add.w File_RatioSeg_Buf_Downloads(a0),d1 ; Restdownloadanzahl erhoehen
  239.  move.w d1,UserDat_DownLeft(a6)        ; Restdownloadanzahl speichern
  240.  
  241. ** Restdownloadbytes erhoehen
  242.  
  243. SubDownload_AddBytes:
  244.  move.l UserDat_DownBytesLeft(a6),d1    ; Restdownloadbytes in d1
  245.  cmp.l #UserDat_DownBytesLeft_Unlimited,d1 ; Unendlich viele Restdownloadbytes ?
  246.  beq.s SubDownload_End            ; Ja -> Ende
  247.  add.l File_RatioSeg_Buf_DownBytes(a0),d1 ; Restdownloadbytes erhoehen
  248.  bcs.s SubDownload_SetMax        ; Ueberlauf, verzw.
  249.  cmp.l #UserDat_DownBytesLeft_Max,d1    ; Maximum ueberschritten ?
  250.  bls.s SubDownload_Set            ; Nein, verzw.
  251. SubDownload_SetMax:            ; Nein, Ueberlauf
  252.  move.l #UserDat_DownBytesLeft_Max,d1    ; Maximum in d1
  253. SubDownload_Set:
  254.  move.l d1,UserDat_DownBytesLeft(a6)    ; Restdownloadbytes speichern
  255.  
  256. ** Ende
  257.  
  258. SubDownload_End:
  259.  move.l Main_UserLib(a5),a6        ; Userbase in a6
  260.  jsr User_WaitOFF(a6)            ; User-Zugriff erlauben
  261.  movem.l (sp)+,d1/a6            ; Register holen
  262.  rts
  263.  
  264.  
  265.  
  266. *************************************************
  267. *
  268. * NAME      : AddUpload
  269. *
  270. * FUNKTION: Ein Upload-File zu Download-Restdaten addieren
  271. *        - Ratio wird hier benutzt
  272. *
  273. * INPUT      : d0.l: Laenge des Download-Files
  274. *        d7.w: Filebrettnummer (-1=kein Filebrett)
  275. *
  276. * OUTPUT  : keine
  277. *
  278. *************************************************
  279. AddUpload:
  280.  movem.l d0-d4/a0/a6,-(sp)        ; Register retten
  281.  
  282.  bsr WhichRatio                ; Ratioart in d4 holen
  283.  
  284.  move.l Main_UserLib(a5),a6        ; Userbase in a6
  285.  jsr User_WaitON(a6)            ; User-Zugriff sperren
  286.  
  287.  move.l Main_User(a5),a0        ; Zeiger auf Userdaten in a0
  288.  
  289. ** Restdownloadanzahl erhoehen
  290.  
  291.  btst #RatioB_UpDown,d4            ; Download-Ratio erlaubt ?
  292.  beq.s AddUpload_Down_End        ; Nein, verzw.
  293.  moveq #0,d2                ; d2 loeschen
  294.  move.b UserDat_DownUp(a0),d2        ; Downloadanzahl-Ratio in d2
  295.  beq.s AddUpload_Down_End        ; Wenn Null (ausgestellt), verzw.
  296.  move.w UserDat_DownLeft(a0),d1        ; Restdownloadanzahl in d1
  297.  cmp.w #UserDat_DownLeft_Unlimited,d1    ; Unendlich viele Restdownloads ?
  298.  beq.s AddUpload_Down_End        ; Ja, verzw.
  299.  add.w d2,d1                ; Up-Down-Ratio addieren
  300.  cmp.w #UserDat_DownLeft_Max,d1        ; Max. Anzahl ueberschritten ?
  301.  bls.s AddUpload_Down_Set        ; Nein, verzw.
  302.  move.w #UserDat_DownLeft_Max,d1    ; Max. Anzahl in d1
  303. AddUpload_Down_Set:
  304.  move.w d1,UserDat_DownLeft(a0)        ; Restdownloadanzahl speichern
  305. AddUpload_Down_End:
  306.  
  307. ** Restdownloadbytes erhoehen
  308.  
  309.  btst #RatioB_UpByte,d4            ; Byte-Ratio erlaubt ?
  310.  beq.s AddUpload_Byte_End        ; Nein, verzw.
  311.  moveq #0,d1                ; d1 loeschen
  312.  move.b UserDat_DownUpBytes(a0),d1    ; Faktor in d1
  313.  beq.s AddUpload_Byte_End        ; Wenn Null (ausgestellt), verzw.
  314.  move.l UserDat_DownBytesLeft(a0),d2    ; Restdownloadbytes in d2
  315.  cmp.l #UserDat_DownBytesLeft_Unlimited,d2 ; Unendlich viele Restdownloadbytes ?
  316.  beq.s AddUpload_Byte_End        ; Ja, verzw.
  317.   add.l #512,d0                ; Filelaenge in KByte umrechnen,
  318.   lsr.l #8,d0                ; runde dabei in der Mitte
  319.   lsr.l #2,d0                ; d0=(d0+512)/1024
  320. ** 16 Bit * 32 Bit-Multiplikation
  321.  move.l d0,d3                ; Bits 16-31 der Laenge in d3
  322.  swap d3
  323.  mulu d1,d3                ; Obere 16 Bits mit Faktor multiplizieren
  324.  swap d3                ; Um 16 Bits nach oben shiften
  325. ; clr.w d3                ; Unteres Wort loechen
  326.  mulu d1,d0                ; Untere 16 Bits mit Faktor multiplizieren
  327.  add.l d3,d0                ; Beide Werte addieren
  328.  bcs.s AddUpload_Byte_SetMax        ; Wenn Ueberlauf, verzw.
  329.  add.l d2,d0                ; Alten Restwert und neuen Wert summieren
  330.  bcs.s AddUpload_Byte_SetMax        ; Wenn Ueberlauf, verzw.
  331. **
  332.  cmp.l #UserDat_DownBytesLeft_Max,d0    ; Maximum ueberschritten ?
  333.  bls.s AddUpload_Byte_SetBytes        ; Nein, verzw.
  334. AddUpload_Byte_SetMax:            ; Nein, Ueberlauf
  335.  move.l #UserDat_DownBytesLeft_Max,d0    ; Maximum in d0
  336. AddUpload_Byte_SetBytes:
  337.  move.l d0,UserDat_DownBytesLeft(a0)    ; Restdownloadbytes speichern
  338. AddUpload_Byte_End:
  339.  
  340. ** Ende
  341.  
  342.  move.l Main_UserLib(a5),a6        ; Userbase in a6
  343.  jsr User_WaitOFF(a6)            ; User-Zugriff erlauben
  344.  movem.l (sp)+,d0-d4/a0/a6        ; Register holen
  345.  rts
  346.  
  347.  
  348.  
  349. *************************************************
  350. *
  351. * NAME      : WhichRatio
  352. *
  353. * FUNKTION: Pruefe, ob durch den Brettkommentar die Ratio-Art
  354. *        eingeschraenkt ist
  355. *        - Steht im Brettkommentar ein BYTE: am Anfang, so
  356. *          wird nur die Byteratio benutzt
  357. *        - Steht im Brettkommentar ein DOWN: am Anfang, so
  358. *          wird nur die Downloadratio benutzt
  359. *
  360. * INPUT      : d7.w: Filebrettnummer (-1=kein Filebrett)
  361. *
  362. * OUTPUT  : d4.w: Art der Ratio (Bit0(s)=ByteRatio / Bit1(s)=Downloadratio)
  363. *
  364. *************************************************
  365. WhichRatio:
  366.  movem.l a0/a1/a6,-(sp)            ; Register retten
  367.  
  368.  tst.w d7                ; Filebrett ?
  369.  bmi.s WhichRatio_Both            ; Nein -> Beide Arten erlauben
  370.  
  371.  move.l Main_TextLib(a5),a6        ; Textbase in a6
  372.  
  373.  move.l Main_FileLib(a5),a1        ; Filebase in a1
  374.  move.l File_Comment(a1),a1        ; Zeiger auf Kommentartabelle in a1
  375.  move.w d7,d4                ; Zeiger auf Kommentar in a1 errechnen
  376.  mulu #File_CommentLength,d4
  377.  add.l d4,a1
  378.  
  379.  moveq #RatioF_UpByte+RatioF_DoByte,d4    ; Nur Byteratio beim Upload&Download in d4
  380.  lea T_OnlyByteRatio(pc),a0        ; Zeiger auf Wildcard-String in a0
  381.  jsr Text_STCompare(a6)            ; Vergleiche beide Strings
  382.  beq.s WhichRatio_End            ; Gleich -> Byteratio
  383.  
  384.  moveq #RatioF_UpDown+RatioF_DoDown,d4    ; Nur Downloadratio beim Upload & Download in d4
  385.  lea T_OnlyDownRatio(pc),a0        ; Zeiger auf Wildcard-String in a0
  386.  jsr Text_STCompare(a6)            ; Vergleiche beide Strings
  387.  beq.s WhichRatio_End            ; Gleich -> Downratio
  388.  
  389.  moveq #RatioF_UpByte+RatioF_DoByte+RatioF_ErrDown,d4 ; Nur Byteratio beim Upload in d4
  390.  lea T_ByteRatio(pc),a0            ; Zeiger auf Wildcard-String in a0
  391.  jsr Text_STCompare(a6)            ; Vergleiche beide Strings
  392.  beq.s WhichRatio_End            ; Gleich -> Byteratio
  393.  
  394.  moveq #RatioF_UpDown+RatioF_DoDown+RatioF_ErrByte,d4 ; Nur Downloadratio beim Upload in d4
  395.  lea T_DownRatio(pc),a0            ; Zeiger auf Wildcard-String in a0
  396.  jsr Text_STCompare(a6)            ; Vergleiche beide Strings
  397.  beq.s WhichRatio_End            ; Gleich -> Downratio
  398.  
  399. WhichRatio_Both:            ; Alle Ratios erlaubt in d2
  400.  moveq #RatioF_UpByte+RatioF_UpDown+RatioF_DoByte+RatioF_DoDown,d4
  401.  
  402. WhichRatio_End:
  403.  movem.l (sp)+,a0/a1/a6            ; Register holen
  404.  rts
  405.  
  406.  
  407.  
  408. ***** DATENABSCHNITT
  409.  
  410.  
  411. T_Version:    dc.b    "AMMS-RatioSeg V1.13",0
  412. T_ByteRatio:    dc.b    "BYTE:*",0
  413. T_DownRatio:    dc.b    "DOWN:*",0
  414. T_OnlyByteRatio: dc.b    "ONLYBYTE:*",0
  415. T_OnlyDownRatio: dc.b    "ONLYDOWN:*",0
  416.  
  417.  
  418.